<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>出入库记录</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="/resource/css/common.css" />
		<link rel="stylesheet" href="/resource/css/layui.css" media="all">
		<link rel="stylesheet" href="/resource/css/system.css" />
	</head>
	<body>
	<div class="formHead">
		<form class="layui-form changelabelWidth">
			<div class="layui-inline">
				<label class="layui-form-label">出入库类型</label>
				<div class="layui-input-inline">
					<select name="status">
						<option value="">所有类型</option>
						<option value="1">出库</option>
						<option value="0">入库</option>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">时间从</label>
				<div class="layui-input-inline">
					<input type="text" name="startTime" id="startTime" readonly class="layui-input"/>
				</div>
                到
				<div class="layui-input-inline">
					<input type="text" name="endTime" id="endTime" readonly class="layui-input"/>
				</div>
			</div>
			<div class="layui-inline">
				<button class="layui-btn layui-btn-normal" lay-submit lay-filter="query">查询</button>
			</div>
		</form>
		</div>
		<table class="layui-hide layui-table" id="dataTable" lay-filter="dataTable"></table>
		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-normal" lay-event="detail">详情</a>
		</script>
		<script src="/resource/layui.js" charset="utf-8"></script>
			<script src="/resource/layui.js" charset="utf-8"></script>
			<script>
                var token=(new parent.window._user()).getData('token');
                var where={
                    "_token":token,
                    "companyCode":(new parent.window._user()).getData('venderCode'), //厂商编号
                    "productCode":(new parent.window._user()).getData('productCode'),  //产品名称编号
                    "modelNumber":(new parent.window._user()).getData('versionCode')  //产品型号
                }
                layui.use(['table','laydate','form','laypage','layer'], function() {
                    var table = layui.table//表格
                        ,laydate = layui.laydate //日期
                        ,laypage = layui.laypage //分页
                        ,form = layui.form//表单
                        ,layerTips = parent.layer === undefined ? layui.layer : parent.layer
                        ,$ = layui.jquery
                        ,layer = layui.layer; //独立版的layer无需执行这一句


                    //日期时间选择器
                    laydate.render({
                        elem: '#startTime'
                        ,type: 'datetime'
                    });
                    laydate.render({
                        elem: '#endTime'
                        ,type: 'datetime'
                    });
                    form.on('submit(query)', function(data){
                        where={
                            "_token":token,
                            "companyCode":(new parent.window._user()).getData('venderCode'), //厂商编号
                            "productCode":(new parent.window._user()).getData('productCode'),  //产品名称编号
                            "modelNumber":(new parent.window._user()).getData('versionCode')  //产品型号
                        }
                        $.extend( where, data.field );
                        table.reload('dataTable', {
                            where: where
                            ,page: {
                                curr: 1 //重新从第 1 页开始
                            }});
                        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                    });

                    //出库表格
                    table.render({
                        elem: '#dataTable'
                        ,url: '/storerecord/query'
                        ,page: true // 是否开启分页
                        ,limit : 10
                        ,method: 'get'					// 请求类型 默认get
                        ,where: where
                        ,cols: [
                            [ {
                                field: 'product',
                                width: 120,
                                title: '产品名称'
                            }, {
                                field: 'version',
                                width: 120,
                                title: '规格、型号',
                            }, {
                                field: 'vender',
                                width: 120,
                                title: '厂家',
                            },{
                                width: 80,
                                title: '出入库类型',
                                templet:function(d){
                                    if(d.status=='0'){
                                        return '入库';
									}else {
                                        return '出库';
									}
                                }
                            },{
                                field: 'storeRegionValue',
                                width: 180,
                                title: '库存所在地'
                            }, {
                                field: 'operationTime',
                                width: 180,
                                title: '出入库时间'
                            }, {
                                field: 'operator',
                                width: 180,
                                title: '出入库操作人',
                            }, {
                                field: 'phone',
                                width: 120,
                                title: '联系电话'
                            },{
                                field: 'unitPrice',
                                width: 80,
                                title: '单价',
                                sort: true
                            }, {
                                field: 'amount',
                                width: 80,
                                title: '数量',
                                sort: true
                            }, {
                                width: 80,
                                title: '总价',
                                sort: true,
                                templet:function(d){
                                    return d.amount*d.unitPrice
                                }
                            },{
                                field: 'remark',
                                width: 80,
                                title: '备注'
                            }, {
                                field: "right",
                                width: 80,
                                title: '详情',
                                align: 'center',
                                toolbar: '#barDemo'
                            }]
                        ]

                    });
                    //监听工具条
                    table.on('tool(dataTable)', function(obj) {
                        var data = obj.data;
                        if(obj.event === 'detail') {
                            console.log("点击")
                            showform(obj,"show");
                        }
                    });

                    function showform(formData){
                        console.log(formData)
						var olddata = formData.data;
                        //判断是否已弹出表单
                        if(document.getElementById("formDiv")){
                            return;
                        }
                        $.get('record-detailform.html' , function(form) {
                            addBoxIndex = layer.open({
                                type: 1,
                                title: '出入库记录',
                                content: form,
                                btn: '',
                                shade: false,
                                offset: ['80px', '15%'],
                                area: ['800px', '400px'],
                                zIndex: 999,
                                maxmin: true,
                                yes: function(index) {
                                    //触发表单的提交事件
                                    $('form.layui-form').find('button[lay-filter=edit]').click();
                                },
                                full: function(elem) {
                                    var win = window.top === window.self ? window : parent.window;
                                    $(win).on('resize', function() {
                                        var $this = $(this);
                                        elem.width($this.width()).height($this.height()).css({
                                            top: 0,
                                            left: 0
                                        });
                                        elem.children('div.layui-layer-content').height($this.height() - 95);
                                    });
                                },
                                success: function(layero, index) {
                                    //弹出窗口成功后渲染表单
                                    var form2 = layui.form;
                                    if(olddata){
                                        $('input[name=product]').val(olddata.product);//产品名称
										$('input[name=typeModel]').val(olddata.version);//规格型号
										$('input[name=vender]').val(olddata.vender);//厂家
                                        $('input[name=type]').val('');//出入库类型
                                        $('input[name=address]').val('');//库存所在地
                                        $('input[name=depotTime]').val(olddata.operationTime);//出入库时间
                                        $('input[name=depotPerson]').val(olddata.operator);//操作人
                                        $('input[name=telphone]').val(olddata.phone);//联系电话
                                        $('input[name=singlePrice]').val(olddata.unitPrice);//单价
                                        $('input[name=amount]').val(olddata.amount);//数量
                                        $('input[name=totalPrice]').val(olddata.unitPrice * olddata.amount);//总价
                                        $('textarea[name=remark]').val(olddata.remark);//备注
									}
                                    form2.render();

                                }
                            });
                        });
                    }

                });
			</script>

	</body>

</html>